{{>head}}


<h1>Settings</h1>
<form id="frmSettings">
	When i add new links:
	<br /><br />
	<label><input type="checkbox" id="postToFile" {{postToFile}} /> Dump to file</label>
	<label><input type="checkbox" id="postToCVEx" {{postToCVEx}} /> Post to www.cityvilleexchange.com</label>
	<label><input type="checkbox" id="postToCVLinkEx" {{postToCVLinkEx}} /> Post to www.cityvillelinkexchange.com</label>
	<br /><br />
	<label><input type="checkbox" id="showImages" {{showImages}} /> Display Images</label>
	<br /><br />
	<input type="button" class="button" id="btnSaveSettings" value="Update" />
</form>

<h1 style="margin-top: 20px">Maintainance</h1>
<form>
<input type="button" class="button" id="btnUpdateDB" value="Update Virals Now" />
<input type="button" class="button" id="btnClearAllFiles" value="Clear All Files" />
</form>

<script type="text/javascript">
	$(function(){
		$("#btnUpdateDB").click( function(e){
			$.post("Main.php?act=updateDBNow",{},
				function(r){ 
					if (r.resp)
					{
						alert("Stats\nFound in XML: "+r.inXML+"\nFound in DB: "+r.inDB+"\nAdded: "+r.added); 
						return;
					} 
					alert("oops"); 
			},"json")
			.error(function(){ alert("ooops"); });
		});

		$("#btnClearAllFiles").click( function(e){
			var cnf = confirm("Are you sure you want to delete all dumps?");
			if (!cnf) return;

			$.post("Main.php?act=deleteAllDumps",{},
				function(r)
				{ 
					if (r.resp)
					{
						alert("Removed "+r.filesRemoved+" files"); 
						return;
					} 
					alert("oops"); 
				}
			,"json")
			.error(function(){ alert("ooops"); });
		});

		$("#btnSaveSettings").click(function(e) {
			e.preventDefault();

			//get settings
			var pObj = {};
			$("#frmSettings :checkbox").each(function(i,el){
				var $el = $(el);
				pObj[$el.attr("id")] = $el.is(":checked")?1:0;
			});

			$.post("Main.php?act=saveSettings", $.toJSON(pObj), 
				function(r){
					if (r.resp)
					{
						alert("Saved");
						return;
					}

					alert("ooops");
				}
			,"json")
			.error(function() { alert("oops"); });
				
		});
	});
</script>
{{>foot}}